package infostroy.bookagolf.components.controls;

import infostroy.bookagolf.common.enums.Tabs;
import infostroy.bookagolf.common.helpers.ImageHelper;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * Created by valer_000 on 1/22/14.
 */
public class ToggleButton extends JButton {

    private BufferedImage inactiveImg;
    private BufferedImage activeImg;

    private boolean active;

    public ToggleButton(Tabs tab, boolean active) {
        this.active = active;
        this.setFocusPainted(false);
        this.setBorderPainted(false);
        activeImg = ImageHelper.getInstance().loadImage(tab.getActiveImg());
        inactiveImg = ImageHelper.getInstance().loadImage(tab.getInactiveImg());
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (active) {
            g.drawImage(activeImg, 0, 0, null);
        } else {
            g.drawImage(inactiveImg, 0, 0, null);
        }
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(inactiveImg.getWidth(), inactiveImg.getHeight());
    }

    public void setActive(boolean active) {
        this.active = active;
    }
}
